<template>
    <v-btn icon :color="flwStatus ? 'indigo': null" @click="flwToggle">
        <v-icon>mdi-heart</v-icon>
        关注
    </v-btn>
</template>

<script>
export default {
    data(){
        return {
            flwStatus: false,
            actions: {
                type: 'Personage',
                object: '',
                name: 'follow'
            }
        }
    },
    props: {
      object: {
        type: String,
        required: true
      },
    },
    methods: {
        async getFlwStatus(){
            if(this.$axios.defaults.headers.common.Authorization){
                this.actions.object = this.object
                const res = await this.$axios.$get('actions/status', {
                    params:this.actions 
                })
                this.flwStatus = res.status
            }
        },
        async flwToggle(){
            if(this.$axios.defaults.headers.common.Authorization){
                this.actions.object = this.object
                const res = await this.$axios.$post('actions/toggle',this.actions)
                this.flwStatus = res.status
                if(res.status){
                    this.$toast.success('关注成功')
                }else{
                    this.$toast.show('取消关注')
                }
            }else{
                this.$toast.error('请先登录')
            }
        }
    },
    mounted(){
        this.getFlwStatus()
    }

}
</script>

<style>

</style>